var $ = exports

$.AssertionError = function(msg) {
	this.name = "AssertionError"
	this.message = msg
}

$.AssertionError.prototype.toString = function() {
	return this.name + ":" + this.message
}

$.fail = function(msg) {
	throw new $.AssertionError(msg || "")
}

$.ok = function(value, msg) {
	if (!!!value) {
		$.fail(msg || "" + value + " should be OK")
	}
}

$.raises = function(block, expectedError, msg) {
	var ex = null;
	try {
		block();
	} catch (e) {
		ex = e
	}
	
	if (ex instanceof expectedError) {
		// Everything is OK
	} else if (ex == null) {
		$.fail("" + expectedError + " should be raised: " + msg)
	} else {
		$.fail("Should raise " + expectedError + " but " + ex + " was raised: " + msg)
	}
}

$.equal = function(expected, actual, msg) {
	$.ok( actual == expected, 
		"Expected " + expected + " but was " + actual + (msg ? ". " + msg : "") 
	)
}

$.javaEqual = function(expected, actual, msg) {
	$.ok( expected.equals(actual), 
		"Expected " + expected + " but was " + actual + (msg ? ". " + msg : "") 
	)
}
